package weixin.core.Handles;

import com.github.sd4324530.fastweixin.api.OauthAPI;
import com.github.sd4324530.fastweixin.api.enums.OauthScope;
import com.github.sd4324530.fastweixin.handle.MessageHandle;
import com.github.sd4324530.fastweixin.message.*;
import com.github.sd4324530.fastweixin.message.req.TextReqMsg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 微信文本消息拦截器
 * Created by lxb on 2015/12/22.
 */
@Component
public class MyTextMessageHandle implements MessageHandle<TextReqMsg>{
    private static final Logger LOG  = LoggerFactory.getLogger(MyTextMessageHandle.class);
    @Autowired
    private OauthAPI OauthAPI;
    public BaseMsg handle(TextReqMsg textReqMsg) {
        LOG.info("发送者:"+textReqMsg.getFromUserName()+"---接收到的消息为:" + textReqMsg.getContent()+
                "消息类型："+textReqMsg.getMsgType());
        if("你好".equals(textReqMsg.getContent())){
            return new TextMsg("你好我好大家好");
        }else if("音乐".equals(textReqMsg.getContent())){
            VoiceMsg voiceMsg=new VoiceMsg("90SLott3azc0tyaW2b-y-gUsYn5yaPYhVO0r4-gbRvQ");
            System.out.println(voiceMsg);
            return  voiceMsg;
        }
        else if("图文消息".equals(textReqMsg.getContent())){
            NewsMsg newsMsg=new NewsMsg();
            newsMsg.setMaxSize(4);
            List<Article> articleList=new ArrayList<Article>();
            Article article=new Article();
            article.setUrl("http://bb15662683581.vicp.cc/sdktest/jssdk");
            article.setDescription("第一个图文");
            article.setPicUrl("http://sd.hope123.net/static/pub/img/service_2.jpg");
            article.setTitle("第一个图文的标题");
            Article article1=new Article();
            article1.setUrl("www.baidu.com");
            article1.setDescription("第二个图文");
            article1.setPicUrl("http://sd.hope123.net/static/pub/img/service_3.jpg");
            article1.setTitle("第二个图文的标题");
            article1.setUrl(OauthAPI.getOauthPageUrl("http://bb15662683581.vicp.cc/sdktest/jssdk", OauthScope.SNSAPI_USERINFO,"001"));
            Article article2=new Article();
            article2.setUrl("www.baidu.com");
            article2.setDescription("第三个图文");
            article2.setPicUrl("http://sd.hope123.net/static/pub/img/service_4.jpg");
            article2.setTitle("第三个图文的标题");
            Article article3=new Article();
            article3.setUrl("www.baidu.com");
            article3.setDescription("第一个图文");
            article3.setPicUrl("http://sd.hope123.net/static/pub/img/service_1.jpg");
            article3.setTitle("第四个图文的标题");
            articleList.add(article);
            articleList.add(article1);
            articleList.add(article2);
            articleList.add(article3);
            newsMsg.setArticles(articleList);
            return newsMsg;
        }
        return new TextMsg("你发的啥我不知道");
    }

    public boolean beforeHandle(TextReqMsg textReqMsg) {
        return true;
    }
}
